﻿using System.Data;
using Algorithms.Common.Data;
using NUnit.Framework;

namespace ProfileTableDqEstimator
{
    [TestFixture]
    public class ProfileTableDqEstimatorUnitTests
    {
        [Test]
        public void ExecuteAlgorithmNeedsGrpId()
        {
            var header = "Something,SomeOtherThing".Split(",".ToCharArray());
            var exec = new ProfileTableDqEstimatorAlgExecuter();
            var query = ProfTableQueryHelper.Parse("a=b ^ c=d");
            Assert.Throws<DataException>(() => exec.ExecuteAlgorithm(query, header, new string[][] {} ));
        }

        [Test]
        public void RunQuery()
        {
            var header = "grp_id,Brand,Model,Price".Split(",".ToCharArray());
            var data = new[]
                           {
                               "7,,,",
                               "3,S,,",
                               "1,S,S,",
                               "0,S,S,H"
                           };
            var query = ProfTableQueryHelper.Parse("Brand=S ^ Model=S ^ Price=L");
            var exec = new ProfileTableDqEstimatorAlgExecuter();
            var res = exec.ExecuteAlgorithm(query, header, CsvHelper.BasicCsvToArray(data));

            Assert.That(res, Is.EqualTo("1,S,S,"));
        }
    }
}
